﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using U.B.DoMain.工作流引擎.Models;

namespace U.B.DoMain.工作流引擎
{
    public class LoginWorkflows
    {
        private readonly IWorkflow _workflow;

        public LoginWorkflows(IWorkflow workflow)
        {
            _workflow = workflow;
        }

        public async Task<bool> ExecuteApprovalWorkflow(ApprovalWorkflowData data)
        {
            try
            {
                // 执行工作流步骤
                bool isValid = await _workflow.ValidateRequest(data);
                if (!isValid)
                {
                    Console.WriteLine("请假申请验证失败");
                    return false;
                }

                bool hasPermission = await _workflow.CheckPermissions(data);
                if (!hasPermission)
                {
                    Console.WriteLine("审批人权限验证失败");
                    return false;
                }

                await _workflow.ProcessApproval(data);
                await _workflow.NotifyParticipants(data);
                await _workflow.UpdateWorkflowStatus(data);

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"工作流执行异常: {ex.Message}");
                return false;
            }
        }
    }
}
